<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form
          ref="queryForm"
          :inline="true"
          label-width="68px"
        >
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['chuwei:add']"
              >新增</el-button
            >
          </el-col>
          <!-- <right-toolbar
            :showSearch.sync="showSearch"
            @queryTable="getList"
          ></right-toolbar> -->
        </el-row>

        <el-table
          :data="userList"
          @selection-change="handleSelectionChange"
          style="width: 100%"
        >
          <el-table-column type="selection" width="50" align="center" />

          <el-table-column
            label="名称"
            align="center"
            prop="houseCabinet"
            :show-overflow-tooltip="true"
            width="520"
          />

          <el-table-column
            label="创建时间"
            align="center"
            prop="createTime"
            width="520"
          >
            <!-- <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template> -->
          </el-table-column>

          <!-- <el-table-column
            label="备注"
            align="center"
            prop="remark"
            width="460"
          /> -->
          <el-table-column
            label="操作"
            align="center"
            width="400"
            fixed="right"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['chuwei:Modify']"
                >修改</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <!-- <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        /> -->
      </el-col>
    </el-row>

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="储位名称" prop="houseCabinet">
              <el-input
                v-model="form.houseCabinet"
                placeholder="请输入储位名称"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 修改 -->
        <el-dialog :title="title" :visible.sync="open1" width="600px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-row>
                <el-col :span="12">
                    <el-form-item label="储位名称" prop="warehouseName">
                    <el-input
                        v-model="form.houseCabinet"
                        placeholder="请输入储位名称"
                    />
                    </el-form-item>
                </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm1">确 定</el-button>
                <el-button @click="cancel1">取 消</el-button>
            </div>
    </el-dialog>
  </div>
</template>

<script>
import { cabinetList ,addCabinet ,updateCabinet} from "@/api/system/stores";
export default {
  components: {},
  props: [],
  data(){
    return{
        userList:[],
        title: "",
        open:false,
        open1:false,
        query:{
          type:1
        },
        form:{
            houseCabinet:'',
            type:''
        },
        rules: {
          houseCabinet: [
            { required: true, message: '请输入储位名称 ', trigger: 'blur' },
          ],
        },
    }
  },
  watch:{},
  computed: {},
  created(){
      this.getList()
  },
  mounted(){},
  methods:{
    getList() {
      cabinetList(this.query).then(res => {
        console.log(res);
        if(res.code == 200){
            this.userList = res.rows;
        }
       }
      )
    },
     
      handleSelectionChange(){
          console.log(111)
          this.open = true
      },
      handleAdd(){
          this.form = {}
          this.title =  "新增储位"
          this.open = true
      },
      handleUpdate(row){
          this.title =  "编辑储位"
          this.open1 = true
          this.form = row
          console.log(row.id)
      },
      submitForm(){
          this.$refs["form"].validate(valid => {
            if (valid) {
              let data = {
                 houseCabinet:this.form.houseCabinet,
                  type:1
              }
                addCabinet(data).then(res => {
                this.msgSuccess("添加成功");
                this.open = false;
                this.getList();
                console.log(res);
                });
            }
        });
      },
      cancel(){
          this.open = false
      },
      submitForm1(){
          this.$refs["form"].validate(valid => {
            if (valid) {
                updateCabinet(this.form).then(res=>{
                    console.log(res)
                     this.msgSuccess("修改成功");
                    this.open1= false;
                    this.getList();
                    console.log(res);
                })
            }
        });
      },
      cancel1(){
          this.open1 = false
      }
  }
}
</script>

<style lang="scss" scoped>

</style>
